package com.azier.kapacitor.script.node;

import com.azier.kapacitor.script.method.*;
import com.azier.kapacitor.script.node.nodebind.*;
import com.azier.kapacitor.script.node.nodebind.qlnodebind.*;

import java.util.ArrayList;

/**
* 1 * @Author: luoj
* 2 * @Date: 2019/11/8 11:27
* 3
*/

/**
Creates a new stream node that can be further filtered using the Database, RetentionPolicy, Measurement and Where properties. From can be called multiple times to create multiple independent forks of the data stream.
**/
/**
创建一个新的流节点，该节点可以使用Database，RetentionPolicy，Measurement和Where属性进行进一步过滤。可以多次调用From，以创建数据流的多个独立派生。
**/
public class FromNode extends AbstractNode implements AlertNodeBind, BarrierNodeBind, BottomNodeBind, ChangeDetectNodeBind, CombineNodeBind, CountNodeBind,
        CumulativeSumNodeBind, DefaultNodeBind, DeleteNodeBind, DerivativeNodeBind, DifferenceNodeBind, DistinctNodeBind, Ec2AutoscaleNodeBind,
        ElapsedNodeBind, EvalNodeBind, FirstNodeBind, FlattenNodeBind, FromNodeBind, HoltWintersNodeBind, HoltWintersWithFitNodeBind, HttpOutNodeBind,
        HttpPostNodeBind, InfluxDBOutNodeBind, JoinNodeBind, K8sAutoscaleNodeBind, KapacitorLoopbackNodeBind, LastNodeBind, LogNodeBind, MaxNodeBind,
        MeanNodeBind, MedianNodeBind, MinNodeBind, ModeNodeBind, MovingAverageNodeBind, PercentileNodeBind, SampleNodeBind, ShiftNodeBind,
        SideloadNodeBind, SpreadNodeBind, StateCountNodeBind, StateDurationNodeBind, StatsNodeBind, StddevNodeBind, SumNodeBind, SwarmAutoscaleNodeBind,
        TopNodeBind, UnionNodeBind, WindowNodeBind {
    private static final String name = "from";

    public FromNode() {
        super(new ArrayList<>(),new ArrayList<>(),name);
    }

    /**
    The database name. If empty any database will be used.
    **/
    /**
    数据库名称。如果为空，则将使用任何数据库。
    **/
    public FromNode database(String from){
        Database database = new Database(from);
        super.addMethod(database);
        return this;
    }
    /**
    Group the data by a set of tags.
    **/
    /**
    通过一组标签对数据进行分组。
    **/
    public FromNode groupBy(Object ...tag){
        GroupBy groupBy = new GroupBy(tag);
        super.addMethod(groupBy);
        return this;
    }
    /**
     Group the data by a set of tags.
     **/
    /**
     通过一组标签对数据进行分组。
     **/
    public FromNode groupByAll(){
        GroupBy groupBy = new GroupBy();
        super.addMethod(groupBy);
        return this;
    }
    /**
    If set will include the measurement name in the group ID. Along with any other group by dimensions.
    **/
    /**
    如果设置，则将测量名称包含在组ID中。连同其他按维度分组。
    **/
    public FromNode groupByMeasurement(){
        GroupByMeasurement groupByMeasurement = new GroupByMeasurement();
        super.addMethod(groupByMeasurement);
        return this;
    }
    /**
    The measurement name If empty any measurement will be used.
    **/
    /**
    测量名称如果为空，将使用任何测量。
    **/
    public FromNode measurement(String from){
        Measurement measurement = new Measurement(from);
        super.addMethod(measurement);
        return this;
    }
    /**
    Suppress all error logging events from this node.
    **/
    /**
    禁止来自此节点的所有错误记录事件。
    **/
    public FromNode quiet(){
        Quiet quiet = new Quiet();
        super.addMethod(quiet);
        return this;
    }
    /**
    The retention policy name If empty any retention policy will be used.
    **/
    /**
    保留策略名称如果为空，将使用任何保留策略。
    **/
    public FromNode retentionPolicy(String from){
        RetentionPolicy retentionPolicy = new RetentionPolicy(from);
        super.addMethod(retentionPolicy);
        return this;
    }
    /**
    Optional duration for rounding timestamps. Helpful to ensure data points land on specific boundaries Example: stream
    **/
    /**
    舍入时间戳的可选持续时间。有助于确保数据点落在特定边界上示例：流
    **/
    public FromNode round(long interval, String durationLiteral){
        Round round = new Round(interval, durationLiteral);
        super.addMethod(round);
        return this;
    }
    /**
    Optional duration for truncating timestamps. Helpful to ensure data points land on specific boundaries Example: stream
    **/
    /**
    截断时间戳的可选持续时间。有助于确保数据点落在特定边界上示例：流
    **/
    public FromNode truncate(long interval, String durationLiteral){
        Truncate truncate = new Truncate(interval, durationLiteral);
        super.addMethod(truncate);
        return this;
    }
    /**
    Filter the current stream using the given expression. This expression is a Kapacitor expression. Kapacitor expressions are a superset of InfluxQL WHERE expressions. See the expression docs for more information.
    **/
    /**
    使用给定的表达式过滤当前流。此表达式是Kapacitor表达式。 Kapacitor表达式是InfluxQL WHERE表达式的超集。有关更多信息，请参见表达式文档。
    **/
    public FromNode where(String lambda){
        Where where = new Where(lambda);
        super.addMethod(where);
        return this;
    }
}